package com.project.projectdemo.conf.filter;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 拦截器注册类
 * 
 * @author liushgc	2020-02-11
 *
 */
@Configuration
public class InterceptorConfiguration implements WebMvcConfigurer {

	/*
	 * 注册拦截器组件
	 * 按注册顺序，执行拦截器组件
	 */
	public void addInterceptors(InterceptorRegistry registry){
		//注册日志拦截器
		LoggerInterceptor loggerInterceptor = new LoggerInterceptor();
		//不拦截的请求 
		//必须加上/error，因为接口不存在的时候，系统会自动调用/error请求，没加上会造成拦截器执行两次
		String[] loggerExcludePath = {"/login","/error"};
		//addPathPatterns是指要拦截的请求，/**代表所有请求，参数可以是String数组，也可以是String
		registry.addInterceptor(loggerInterceptor).excludePathPatterns(loggerExcludePath).addPathPatterns("/**");
		
		
		//其他拦截器注册，按上述要求进行注册
	}
}
